package com.shop.www.service;


import com.shop.www.daoX.UserDAO;
import com.shop.www.daoX.UserDAOImpl;
import com.shop.www.view.ViewBaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

import static com.shop.www.Utils.orempty.notempty;

@WebServlet("/index")
public class Demo04 extends ViewBaseServlet {
       @Override
       protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           super.doGet(request,response);
       }

       @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        request.setCharacterEncoding("utf-8");
           Integer pageNo = 1 ;
           String pageNoStr = request.getParameter("pageNo");
           if(notempty(pageNoStr)){
               pageNo = Integer.parseInt(pageNoStr);
           }
           HttpSession session = request.getSession();
           session.setAttribute("pageNo",pageNo);
           List userlist = null;
        UserDAO userdao = new UserDAOImpl();
            userlist = userdao.userlist(pageNo);
           session.setAttribute("userlist",userlist);
           int usercount = userdao.userCount();
           int pageCount = (usercount+5-1)/5;
           session.setAttribute("pageCount",pageCount);

        super.processTemplate("index",request,response);
    }
}

